#pragma once

#include "ColligereDatabaseItemBase.hpp"

DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_ADD, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_CHANGE, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_REQUEST, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_POST, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_COMMIT_START, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_COMMIT_END, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_DELETE, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_RESTORE, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_QUERIED, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_LIST_COMMIT_START, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_LIST_COMMIT_END, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_LIST_QUERY_ALL_START, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_ITEM_LIST_QUERY_ALL_END, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_USER_REQUEST_CLOSE, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_OPEN_START, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_DATABASE_OPEN_END, -1 )

namespace col 
{

/*! @brief A database event class
 *
 * Used to store information about a database event.
 **/
class DatabaseEventBase : public wxEvent 
{
public:
	DatabaseEventBase ( wxEventType commandType, wxInt32 id,
		const DatabaseItemBase *pItem = 0 );
	virtual ~DatabaseEventBase();

	bool Vetoed() const;
	void Veto ( bool veto = true );

	//! Overrides wxEvent::Clone().
	wxEvent *Clone() const;

	//! Returns a pointer to a item that's associated with this event (if any).
	const DatabaseItemBase *GetItem() const;
protected:
	DatabaseEventBase();
private:
	bool mVetoed;

	// The item that's associated with this event (if any).
	const DatabaseItemBase *mpItem;

// public:
	DECLARE_DYNAMIC_CLASS ( DatabaseEventBase )
};

typedef void ( wxEvtHandler::*DatabaseEventFunction )( DatabaseEventBase & );

class DatabaseRequestEvent : public DatabaseEventBase
{
public:
	DatabaseRequestEvent ( DatabaseItemId itemId, DatabaseItemId itemParentId, 
		const wxString &rItemName, wxUint32 id );
	virtual ~DatabaseRequestEvent();

	wxEvent *Clone() const;

	wxUint32 GetItemId() const;
	wxUint32 GetItemParentId() const;
	const wxString &GetItemName() const;
protected:
	DatabaseRequestEvent();
private:
	const DatabaseItemId mItemId, mItemParentId;
	const wxString mItemName;

// public:
	DECLARE_DYNAMIC_CLASS ( DatabaseRequestEvent )
};

typedef void ( wxEvtHandler::*DatabaseRequestEventFunction )( DatabaseRequestEvent & );

}

///////////////////////////////////
// Ugly macro-mess ahead.
///////////////////////////////////

#define ColligereDatabaseEventHandler (wxObjectEventFunction) \
	( wxEventFunction )( col::DatabaseEventFunction )

#define ColligereDatabaseRequestEventHandler (wxObjectEventFunction) \
	( wxEventFunction )( col::DatabaseRequestEventFunction )